package com.raigor.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.raigor.common.annotation.Log;
import com.raigor.common.core.controller.BaseController;
import com.raigor.common.core.domain.AjaxResult;
import com.raigor.common.enums.BusinessType;
import com.raigor.system.domain.SysUserApikey;
import com.raigor.system.service.ISysUserApikeyService;
import com.raigor.common.utils.poi.ExcelUtil;
import com.raigor.common.core.page.TableDataInfo;

/**
 * 用户apikeyController
 * 
 * @author libaolu
 * @date 2021-12-31
 */
@RestController
@RequestMapping("/system/apikey")
public class SysUserApikeyController extends BaseController
{
    @Autowired
    private ISysUserApikeyService sysUserApikeyService;

    /**
     * 查询用户apikey列表
     */
    @PreAuthorize("@ss.hasPermi('system:apikey:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserApikey sysUserApikey)
    {
        startPage();
        List<SysUserApikey> list = sysUserApikeyService.selectSysUserApikeyList(sysUserApikey);
        return getDataTable(list);
    }

    /**
     * 导出用户apikey列表
     */
    @PreAuthorize("@ss.hasPermi('system:apikey:export')")
    @Log(title = "用户apikey", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserApikey sysUserApikey)
    {
        List<SysUserApikey> list = sysUserApikeyService.selectSysUserApikeyList(sysUserApikey);
        ExcelUtil<SysUserApikey> util = new ExcelUtil<SysUserApikey>(SysUserApikey.class);
        util.exportExcel(response, list, "用户apikey数据");
    }

    /**
     * 获取用户apikey详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:apikey:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(sysUserApikeyService.selectSysUserApikeyByUserId(userId));
    }

    /**
     * 新增用户apikey
     */
    @PreAuthorize("@ss.hasPermi('system:apikey:add')")
    @Log(title = "用户apikey", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserApikey sysUserApikey)
    {
        return toAjax(sysUserApikeyService.insertSysUserApikey(sysUserApikey));
    }

    /**
     * 修改用户apikey
     */
    @PreAuthorize("@ss.hasPermi('system:apikey:edit')")
    @Log(title = "用户apikey", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserApikey sysUserApikey)
    {
        return toAjax(sysUserApikeyService.updateSysUserApikey(sysUserApikey));
    }

    /**
     * 删除用户apikey
     */
    @PreAuthorize("@ss.hasPermi('system:apikey:remove')")
    @Log(title = "用户apikey", businessType = BusinessType.DELETE)
	@DeleteMapping("/{apiKeys}")
    public AjaxResult remove(@PathVariable String[] apiKeys)
    {
        return toAjax(sysUserApikeyService.deleteSysUserApikeyByApiKeys(apiKeys));
    }
}
